import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import axios from 'axios'
import VueAxios from 'vue-axios'
// 全局样式
import "../public/globalStatic.css"
// 树形结构
import TreeTable from 'vue-table-with-tree-grid'
import moment from 'moment'
// 富文本
import VueQuillEditor from 'vue-quill-editor'
// 导入进度条
import NProgress from 'nprogress'




Vue.use(VueQuillEditor, /* { default global options } */)
Vue.prototype.$moment = moment
moment.locale('zh-cn')
Vue.component('tree-table', TreeTable)
Vue.prototype.setLocalValue =function(name,value){
    window.localStorage.setItem(name,JSON.stringify(value))
}
Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

Vue.prototype.getLocalValue =(name)=>{
  JSON.parse(window.localStorage.getItem(name))

}
Vue.prototype.clearLocalValue =(name)=>{
  window.localStorage.clear()

}



// 添加请求拦截器
axios.interceptors.request.use(function (config) {
        // 显示请求条
        NProgress.start();
  // 在发送请求之前做些什么
  config.headers.Authorization=JSON.parse(window.localStorage.getItem('token'))
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 隐藏显示条
    NProgress.done();
  // 对响应数据做点什么
  return response;
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error);
});
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/';
  Vue.prototype.$http= axios

Vue.use(VueAxios, axios)
Vue.config.productionTip = false


new Vue({
 
  router,
  store,
  render: h => h(App)
}).$mount('#app')

